---
--类名: BattleConfirmView.lua
--创建日期: 2015-6-26
--创建人: 陈小虎
--功能描述: 战斗确认视图
--修改内容：
--修改日期:   
--修改人:     
--修改备注: 
--
local MoLayer = require("app.widget.MoLayer")

local BattleConfirmView = class("BattleConfirmView",function()
    return MoLayer.new()--display.newNode()
end)

function BattleConfirmView:ctor(controller,isEscort)
	self.mController = controller
    self.mMaskWidth = display.width
    self.mMaskHeight = display.height / 6 / 4 * 3
	-- local function removeBtn()
 --        self:removeChild(self.mIntoBattle)
 --        self.mIntoBattle = nil
 --        self:removeChild(self.mCancelTaskBattle)
 --        self.mCancelTaskBattle = nil
 --    end

    --ui根节点
    self.mUINode = cc.uiloader:load(Res.HusongUi)
    self:addChild(self.mUINode)
    self.mUINode:setContentSize(cc.size(display.width,display.height))
    ccui.Helper:doLayout(self.mUINode)
    
    local function ok()
        self.mController:okCallback()
        --removeBtn()
    end
    
    local function cancel()
        self.mController:cancelCallback()
        --removeBtn()
    end

    -- local downNode = self.mUINode:getChildByName("Down")
    -- local husongFrame = downNode:getChildByName("husong")
    -- local btnHusong = husongFrame:getChildByName("Button_husong")

    -- local btnCancel = downNode:getChildByName("cancel"):getChildByName("Button_cancel")
    -- local cancelNameNode = btnCancel:getChildByName("name")
    -- local btnBattle = downNode:getChildByName("battle"):getChildByName("Button_battle")


    local bottomNode = self.mUINode:getChildByName("01Bottom")
    -- local btnHusong = bottomNode:getChildByName("03Btn_enter")

    -- local btnBattle = bottomNode:getChildByName("04Btn_battle")
    local btnOk = bottomNode:getChildByName("Button_queding")
    -- if btnOk then
    --     btnOk:setVisible(false)
    -- end

    -- local backContainer = bottomNode:getChildByName("02Btn_back")
    local btnCancel = bottomNode:getChildByName("Button_quxiao")
    local cancelNameNode = btnCancel:getChildByName("name")

    local cancelName = cancelNameNode:getString()

    local battleTextNode = bottomNode:getChildByName("note_batttle")
    local escortTextNode = bottomNode:getChildByName("note_husong")

    if not isEscort then
        escortTextNode:setVisible(false)
    else
        battleTextNode:setVisible(false)
    end
    local function touchEvent_Cancel(sender, eventType)
        
        if eventType == ccui.TouchEventType.began then
        elseif eventType == ccui.TouchEventType.moved then
        elseif eventType == ccui.TouchEventType.ended then
            cancel()
        elseif eventType == ccui.TouchEventType.canceled then

        end
    end
    btnCancel:addTouchEventListener(touchEvent_Cancel)

    local function touchEvent_Ok(sender, eventType)
        
        if eventType == ccui.TouchEventType.began then
        elseif eventType == ccui.TouchEventType.moved then

        elseif eventType == ccui.TouchEventType.ended then
            ok()
        elseif eventType == ccui.TouchEventType.canceled then

        end
    end
    btnOk:addTouchEventListener(touchEvent_Ok)
    -- self.mIntoBattle = ccui.Button:create()
    -- self.mIntoBattle:setTitleText("进入战斗")
    -- self.mIntoBattle:setTitleFontSize(30)
    -- self.mIntoBattle:setPosition(cc.p(display.width / 2, self.mMaskHeight / 2))
    -- self:addChild(self.mIntoBattle)
    -- self.mIntoBattle:addTouchEventListener(function(sender, eventType)
        
    --     if eventType == ccui.TouchEventType.began then
            
    --     elseif eventType == ccui.TouchEventType.moved then
            
    --     elseif eventType == ccui.TouchEventType.ended then
    --         ok()
    --     else
            
    --     end
    -- end)

    -- self.mCancelTaskBattle = ccui.Button:create()
    -- self.mCancelTaskBattle:setTitleText("取消")
    -- self.mCancelTaskBattle:setTitleFontSize(30)
    -- self.mCancelTaskBattle:setPosition(cc.p(display.width / 2 + display.width / 4, self.mMaskHeight / 2))
    -- self:addChild(self.mCancelTaskBattle)
    -- self.mCancelTaskBattle:addTouchEventListener(function(sender, eventType)
        
    --     if eventType == ccui.TouchEventType.began then
            
    --     elseif eventType == ccui.TouchEventType.moved then
            
    --     elseif eventType == ccui.TouchEventType.ended then
    --         cancel()
    --     else
            
    --     end
    -- end)

        
    local startTime = os.time()
    local totalTime = 30
    local function call()
            
        local moveTime = os.time() - startTime
        local syTime = totalTime - moveTime
        if syTime <= 0 then
            cancel()
        else
            -- if self.mCancelTaskBattle then
            --     self.mCancelTaskBattle:setTitleText("取消(" .. syTime .. ")")
            -- end
            if cancelNameNode then
                --btnCancel:setTitleText("取消(" .. syTime .. ")")
                cancelNameNode:setString(cancelName .. "(" .. syTime .. ")")
            end
        end
    end
        
    local action = cc.RepeatForever:create(cc.Sequence:create(cc.CallFunc:create(call)))
    self:runAction(action)
end

return BattleConfirmView